import VueRouter from 'vue-router'
import routes from './routes'
import storage from 'good-storage'

const router = new VueRouter({
  // mode: 'history',
  base: '/hzSystem',
  // history 一定要写 /static
  routes
})

router.beforeEach((to, from, next) => {
  var isLogin = storage.session.get('token')
  var type = storage.session.get('type')
  if (to.path === '/reportTable') {
    isLogin = 'wx000000'
  }
  if (['/oauth-login', '/logout'].includes(to.path)) {
    next()
  } else if (to.path !== '/login' && isLogin === null) {
    next('/login')
  } else if (to.path === '/home') {
    if (type === '0' || type === '1' || type === '2' || type === '9') {
      next('/home/work')
    } else if (type === '4' || type === '7' || type === '8') {
      next('/home/work1')
    } else if (type === '3' || type === '6') {
      next('/chose')
    } else if (type === '5') {
      next('/functional-dep')
    }
  } else {
    next()
  }
})

export default router
